package com.bcu.cn.onlineexamsystem.studentmanage.controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.bcu.cn.onlineexamsystem.user.entity.User;
import com.bcu.cn.onlineexamsystem.studentmanage.service.StudentResourceService;

@Controller
@RequestMapping("/student/resources")
public class StudentResourceController {
    @Autowired
    private StudentResourceService studentResourceService;

    @GetMapping
    public String resourcePage(@RequestParam(required = false) String courseName,
                               @RequestParam(required = false) String type,
                               HttpSession session, Model model) {
        User user = (User) session.getAttribute("user");
        if (user == null || !"student".equals(user.getRole())) {
            return "redirect:/login";
        }
        model.addAttribute("courseList", studentResourceService.getStudentCourseQuestions(user.getUserId(), courseName, type));
        return "student/resource/list";
    }
} 